<template>
    <div>
        {{cartlist}}
        <myheader />
        <br>
        选择分类
        <br>

        <reply :data='cartlist' />
        

        <br>
        <van-field
            v-model="form.name"
            label="分类"
            placeholder="请输入分类"
        />
        <van-field
            v-model="form.level"
            label="等级"
            placeholder="请输入等级"
        />
        <van-field
            v-model="form.params"
            label="参数"
            placeholder="请输入参数"
        />
        
        <van-button type="primary" style="width:200px" @click="addcart">提交</van-button>
    </div>
</template>

<script>

import myheader from '@/components/myheader'
import reply from '@/components/reply'
    export default {
        components:{
            'myheader':myheader,
            'reply':reply
        },
        data(){
            return{
                form:{parent:0},
                token:localStorage.getItem('token'),
                cartlist:{}
                
            }
        },
        methods: {
            addcart(){
                // 父子组件这边递归不好传用local来传父类  更新
                let pid = localStorage.getItem('pid')
                alert(pid)
                //判断有没有父id  有更新 没有加
                if(pid){
                    this.form.parent = pid
                }
                
                    
                this.$axios.post('course/cartM/',this.form).then(res=>{


                })
            },
            //获取数据
            getlist(){
                this.$axios.get('course/cartM/').then(res=>{
                    this.cartlist = {'id':0,'name':'我是顶级类','son':res.data.list}
                })
            }
        },
        mounted() {
            this.getlist()
        },
    }
</script>

<style scoped>

</style>